package com.ziJing.multithreading.atomicity;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @program Multithreading
 * @description:
 * @author: zhangbo
 * @create: 2022/05/01 22:01
 */
public class IPlusPlus {

    private static long n = 0L;

    public static Lock  lock = new ReentrantLock();

    public static void main(String[] args) throws InterruptedException {
        Thread[] threads = new Thread[100];

        CountDownLatch latch = new CountDownLatch(threads.length);

        for (int i = 0; i < threads.length; i++) {
            threads[i] = new Thread(() -> {

                for (int j = 0; j < 10000; j++) {
//                    try{
//                        lock.lock();
                        n++;
//                    } finally {
//                        lock.unlock();
//                    }

                }

                latch.countDown();
            });
        }


        for (Thread t : threads) {
            t.start();
        }

        latch.await();

        System.out.println(n);
    }
}
